<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="isShow">
      <!-- slides -->
      <swiper-slide class="swiper-img" v-for="item of swiperList" :key="item.id">
        <img :src="item.imgUrl" alt="">
      </swiper-slide>
      <!-- 小点点 -->
      <div class="swiper-pagination"  slot="pagination"></div>

      <!--横向滚动条禁用-->
      <!--<div class="swiper-scrollbar"   slot="scrollbar"></div>-->
      <!--左右箭头禁用-->
      <!--<div class="swiper-button-prev" slot="button-prev"></div>-->
      <!--<div class="swiper-button-next" slot="button-next"></div>-->
    </swiper>
  </div>
</template>

<script>
    export default {
        props: ['swiperRes'],
        name: "HomeSwiper",
        data (){
          return {
            swiperOption:{
              pagination: '.swiper-pagination',
              loop:true,
              autoplay:false
            },
            swiperList: []
          }
        },
      // 由于swiperRes是异步获取的，所以无法将值传递给data域，因此要对异步的数据进行监听，当它获取到值时再把值传递给data域中
      watch:{
        swiperRes:function(newVal,oldVal){
          this.swiperList = newVal;
        }
      },
      computed:{
          isShow(){
            return this.swiperList.length
          }
      }
    }
</script>

<style lang="stylus" scoped>

  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff !important
    opacity 0.8
  .wrapper
    overflow:hidden
    width:100%
    height:0
    padding-bottom:26.25%
    background #eee
  .swiper-img img
    width:100%
</style>
